/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * com_ohos_mars_sdt_SdtLogic_Java2C.cc
 *
 *  Created on: 2016年4月11日
 *      Author: caoshaokun
 */

#include "mars/comm/napi/util/comm_function.h"
#include "mars/comm/napi/util/napi_common.h"
#include "mars/baseevent/baseevent.h"
#include "mars/comm/napi/util/var_cache.h"
#include "mars/sdt/sdt_logic.h"
#include "com_ohos_mars_sdt_SdtLogic_JS2C.h"

using namespace mars::sdt;

extern "C" {

/*
 * Class:     com_ohos_mars_sdt_SdtLogic
 * Method:    getLoadLibraries
 * Signature: ()jobject
 */
//JNIEXPORT jobject JNICALL Java_com_ohos_mars_sdt_SdtLogic_getLoadLibraries(JNIEnv *_env, jclass clz)
napi_value JS_com_ohos_mars_sdt_SdtLogic_getLoadLibraries(napi_env env, napi_callback_info info)//packagename.AddClass(class1_path, class1, class2_path, class2, class3_path, class3, ...)
{     
    return mars::baseevent::getLoadLibraries(env);
} 


//JNIEXPORT void JNICALL Java_com_ohos_mars_sdt_SdtLogic_setHttpNetcheckCGI(JNIEnv *_env, jclass clz, jstring cgi)
napi_value JS_com_ohos_mars_sdt_SdtLogic_setHttpNetcheckCGI(napi_env env, napi_callback_info info)
{
  size_t requireArgc = 1; 
  size_t argc = 1; 
  napi_value anArg;
  napi_value *args = &anArg;
  napi_value result;
  NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));    
    
  napi_valuetype valueType;
  NAPI_CALL(env, napi_typeof(env, anArg, &valueType));
  NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. Number expected.");

  std::string strCGI;
  if (napi_ok != GetNAPIStringValue(env, anArg, &strCGI)) {
    napi_create_int32(env, -1, &result);
    return result;
  }
  SetHttpNetcheckCGI(strCGI);
  napi_create_int32(env, 0, &result);
  return result;
}

}

void ExportSDT() {

}
